package test2.recursionAndSort;

import java.util.Map;
import java.util.Stack;

public class Solution2 {

    public boolean checkValidString(String s) {
        // 在此处写入代码
        char[] chars = s.toCharArray();
        Stack<Character> left = new Stack<Character>();
        Stack<Character> xin = new Stack<Character>();

        for (char c : chars) {
            if (c == '(') {
                left.push(c);
                continue;
            }
            if (c == '*') {
                xin.push(c);
                continue;
            }
            if (left.isEmpty() && xin.isEmpty()) {
                return false;
            }
            if (!left.isEmpty()) {
                left.pop();
                continue;
            }
            xin.pop();
        }

        return left.size() <= xin.size();
    }
}
